package com.example.canvastest;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.RectF;
import android.util.AttributeSet;
import android.view.View;

/**
 * Created by 700 on 2018/7/31.
 */

public class DrawOval_DrawPath extends View{

    private RectF rectFstroke = new RectF(10,160,210,260);
    private RectF rectFfill = new RectF(10,310,210,410);
    private Paint movalpaint;
    private Paint mpathpaint;

    public DrawOval_DrawPath(Context context, AttributeSet attrs,
                        int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    public DrawOval_DrawPath(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public DrawOval_DrawPath(Context context) {
        super(context);
    }

    private void initView(){
        movalpaint = new Paint();
        movalpaint.setColor(Color.BLUE);
        mpathpaint = new Paint();
        mpathpaint.setColor(getResources().getColor(
                android.R.color.holo_orange_light
        ));
        mpathpaint.setStyle(Paint.Style.STROKE);//默认为fill，会填充路径所包围的内容！！！！
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        initView();
        movalpaint.setStyle(Paint.Style.STROKE);
        canvas.drawOval(rectFstroke,movalpaint);
        movalpaint.setStyle(Paint.Style.FILL);
        canvas.drawOval(rectFfill,movalpaint);

        Path path = new Path();
        path.moveTo(50,50);
        path.lineTo(100,100);
        path.lineTo(100,300);
        path.lineTo(300,50);
        canvas.drawPath(path,mpathpaint);
    }
}
